import "reflect-metadata";
import React from "react";
import "./index.css";
import ReactDOM from "react-dom/client";
import App from "./App";
import { container } from "./types";
import { InversifyProvider } from "./providers/InversifyProvider";
import { registerModes } from "./config/modes";
import { EditorService } from "./services/EditorService";
import { ToolbarService } from "./services/ToolbarService";
import { PanelService } from "./services/PanelService";
import { ViewService } from "./services/ViewService";
import { MessageService } from "./services/MessageService";
import { ModeRegistry } from "./services/ModeRegistry";
import { IEditorService, IToolbarService, IPanelService, IViewService, IMessageService, IModeRegistry } from "./types";

// 确保容器已经初始化
if (!container.isBound("IModeRegistry")) {
    // 绑定服务
    container.bind<IEditorService>("IEditorService").to(EditorService).inSingletonScope();
    container.bind<IToolbarService>("IToolbarService").to(ToolbarService).inSingletonScope();
    container.bind<IPanelService>("IPanelService").to(PanelService).inSingletonScope();
    container.bind<IViewService>("IViewService").to(ViewService).inSingletonScope();
    container.bind<IMessageService>("IMessageService").to(MessageService).inSingletonScope();
    container.bind<IModeRegistry>("IModeRegistry").to(ModeRegistry).inSingletonScope();
}

// 注册模式
registerModes();

ReactDOM.createRoot(document.getElementById("root")!).render(
    <React.StrictMode>
        <InversifyProvider>
            <App />
        </InversifyProvider>
    </React.StrictMode>
);
